﻿using MediatR;
using Microsoft.AspNetCore.Mvc;
using Reporting.API.Application.Commands.ProductionPlans;
using Reporting.Errorcode;

namespace Reporting.API.Controllers
{
    /// <summary>
    /// 生产计划 --API
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class ProductionPlanController : ControllerBase
    {
        private readonly IMediator _mediator;

        public ProductionPlanController(IMediator mediator)
        {
            _mediator = mediator;
        }

        /// <summary>
        /// 新增生产计划
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult> InsertProductionPlan([FromBody] AddProductionPlanCommand request)
        {
            return await _mediator.Send(request);
        }

        /// <summary>
        /// 显示所有生产计划
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult> GetProductionPlan([FromQuery] GetProductionPlanCommand request)
        {
            return await _mediator.Send(request);
        }

        /// <summary>
        /// 删除生产计划
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<ApiResult> DelProductionPlan([FromQuery] DelProductionPlanCommand request)
        {
            return await _mediator.Send(request);
        }


        /// <summary>
        /// 修改生产计划
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<ApiResult> UpdProductionPlan([FromBody] UpdProductionPlanCommand request)
        {
            return await _mediator.Send(request);
        }

        /// <summary>
        /// id反填-生产计划
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult> ReverseProductionPlan([FromQuery] ReverseProductionPlanCommand request)
        {
            return await _mediator.Send(request);
        }

        /// <summary>
        /// 查询所有的生产计划
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult> SelectCompleteProductionPlan([FromQuery] SelectCompleteProductionPlanCommand request)
        {
            return await _mediator.Send(request);
        }
    }
}
